<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

/**
 * This patch will add the field indexable in for modules_website/page
 */
class core_module_website_0_3_1_Patch001 extends f_package_Patch
{
    public function patch()
    {
        $dbProvider = f_database_Provider::getInstance();

        $tables = array('m_website__page', 'm_website__page_i18n', 'm_website__page_revisions', 'm_website__page_revisions_i18n');

        foreach($tables as $table)
        {
            $dbFields = $dbProvider->setQuery("DESCRIBE ".$table)->execute()->getQueryResults();

            foreach($dbFields as $dbField)
            {
                $fields[] = $dbField['Field'];
            }

            if(!in_array('indexable', $fields))
            {
                $sql = "ALTER TABLE `$table` ADD `indexable` TINYINT( 1 ) NOT NULL DEFAULT '1'";

                $dbProvider->executeQuery($sql);
            }
        }
    }  
}